
#include <stdio.h>

int main() {
    int T; 
    scanf("%d", &T); 

    while (T--) {
        int n; 
        scanf("%d", &n); 

        int matrix[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                scanf("%d", &matrix[i][j]);
            }
        }

        int isUpperTriangular = 1; 


        for (int i = 1; i < n; i++) { 
            for (int j = 0; j < i; j++) {
                if (matrix[i][j] != 0) {
                    isUpperTriangular = 0; 
                    break;
                }
            }
            if (!isUpperTriangular) break;
        }
        if (isUpperTriangular) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }

    return 0;
}


